<template>
  <div class="warning_container">
    <!-- 标题 -->
    <div class="top_box">
      <span class="warning_title">报 警 信 息</span>
      <span class="open_warning_details" @click="openWarningDetails">查看详情</span>
    </div>
    <!-- 内容 -->
    <div class="warning_content">
      <div class="warning_contents">
        <el-table
          :data="warningData"
          border
          fit
          highlight-current-row
          @row-contextmenu="rowContextmenu"
          @row-click="rowMenu.isShow = false"
          @row-dblclick="dblClickRow"
        >
          <el-table-column prop="NAME" label="姓名" width="90" align="center"></el-table-column>
          <el-table-column prop="ALARM_TYPE" label="报警类型" min-width="100" align="center"></el-table-column>
          <el-table-column prop="ALARM_DATE" label="报警时间" min-width="110" align="center"></el-table-column>
          <el-table-column prop="VID" label="人员编号" align="center"></el-table-column>
          <el-table-column prop="CLIENT_NO" label="班组编号" align="center"></el-table-column>
          <el-table-column prop="address" label="报警位置" align="center"></el-table-column>
          <el-table-column prop="LONGITUDE" label="经度" align="center"></el-table-column>
          <el-table-column prop="LATITUDE" label="纬度" align="center"></el-table-column>
        </el-table>
      </div>
    </div>

    <div
      class="rowContextmenu"
      v-if="rowMenu.isShow"
      :style="`top: ${rowMenu.top}px; left: ${rowMenu.left}px`"
    >
      <span @click="exportExcel">导出Excel</span>
      <span>解除报警</span>
      <span>删除图标</span>
    </div>
  </div>
</template>

<script>
import eventBus from '@/eventBus.js'

import export2Excel from '@/utils/exportExcel/index.js'

export default {
  data () {
    return {
      warningData: [],
      rowMenu: {
        top: 0,
        left: 0,
        isShow: false
      },
      row: null,
      personWarning: null
    }
  },
  created () {
    this.getWarningList()
  },
  methods: {
    // 报警信息
    async getWarningList () {
      const { data } = await this.$Http.get(`/DataListCompany/GetCleanerAlarmListApi?ClientNo=${this.$route.query.ClientNo}`)
      this.warningData = data
      eventBus.$emit('warningData', data)
    },
    // 打开报警详情
    openWarningDetails () {
      eventBus.$emit('warningDetails', true)
    },
    // 右键某一行
    rowContextmenu (row, column, event) {
      this.row = row
      window.event.returnValue = false
      this.rowMenu.isShow = true
      this.rowMenu.top = event.clientY
      this.rowMenu.left = event.clientX
      const x = document.body.clientWidth - event.clientX
      if (x < 100) this.rowMenu.left = event.clientX - 100
    },
    // 双击某一行
    dblClickRow (row, column, event) {
      // this.personWarning = this.warningData.find(item => item.NAME === row.NAME && item.ALARM_TYPE === row.ALARM_TYPE)
      // eventBus.$emit('warningItem', this.personWarning)
      eventBus.$emit('warningItem', row)
    },
    // 导出Excel
    exportExcel () {
      this.rowMenu.isShow = false
      const excelName = this.row.NAME + '-报警信息'
      const tHeader = ['人员编号', '姓名', '班组编号', '报警位置', '报警时间', '经度', '纬度', '报警类型']
      const filterVal = ['VID', 'NAME', 'CLIENT_NO', 'address', 'ALARM_DATE', 'LONGITUDE', 'LATITUDE', 'ALARM_TYPE']
      const ary = []
      ary.push(this.row)
      export2Excel(tHeader, filterVal, ary, excelName)
    }
  }
}
</script>

<style scoped lang="less">
.warning_container {
  width: 100%;
  height: 100%;
  border-left: 4px solid #3baefa;
}
.top_box {
  height: 26px;
  line-height: 30px;
  border-bottom: 2px solid #3baefa;
  border-top: 2px solid #3baefa;
  padding-left: 66px;
  display: flex;
  align-items: center;
  .iconfont {
    cursor: pointer;
  }
  .warning_title {
    margin: 0 auto;
    font-weight: bold;
    color: #087ff6;
    cursor: default;
  }
  .open_warning_details {
    float: right;
    margin-right: 10px;
    color: #666;
    cursor: pointer;
    &:hover {
      color: #409eff;
    }
  }
}

.warning_content {
  display: flex;
  height: calc(~'100% - 30px');
  .warning_contents {
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }
}
.details {
  width: 600px;
  height: 400px;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  position: fixed;
  z-index: 99;
}
.rowContextmenu {
  width: 100px;
  height: 78px;
  background-color: #f3f3f3;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 999;
  span {
    display: block;
    text-align: center;
    line-height: 26px;
    font-size: 12px;
    cursor: default;
    &:hover {
      background-color: #409eff;
      color: #fff;
    }
  }
}
</style>
